<!--
 * @Descripttion: 
 * @version: @ 1.0.0
 * @Author: 朱江洲
 * @Date: 2021-11-30 08:53:06
 * @LastEditors: 朱江洲
 * @LastEditTime: 2022-06-01 14:45:51
-->
<template>
  <div class="app-container">
    <div class="header">
      <div class="bread">
        <img src="@/assets/images/icon-people.png" alt="" />
        <span style="margin-left: 10px">缺考人员</span>
      </div>
      <div class="ipt">
        <el-input
          v-model="input"
          placeholder="请输入姓名/考试名称"
          size="normal"
          clearable
          class="ipt-el"
        ></el-input>
        <el-button type="primary" size="default" @click="search">
          搜索
        </el-button>
      </div>
      <div class="btn">
        <el-dropdown>
          <el-button class="el-icon-more"></el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              @click.native="importClue"
              v-hasPermi="['serviceProvide:opportunity:import']"
            >
              导入
            </el-dropdown-item>
            <el-dropdown-item
              @click.native="getExl"
              v-hasPermi="['serviceProvide:opportunity:exportAll']"
            >
              导出
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
    <div class="chooise" v-if="selShow">
      <span>场景：</span>
      <el-select
        v-model="value"
        ref="sel"
        clearable
        @visible-change="(v) => visibleChange(v, 'sel', selClick, admClick)"
        class="sel-sence"
        @change="querySceneList"
      >
        <el-option
          v-for="item in options"
          :key="item.sceneId"
          :label="item.name"
          :value="item.sceneId"
        >
        </el-option>
      </el-select>
      <el-button
        type="primary"
        icon="iconfont icon-shaixuan"
        size="default"
        @click="screen"
      >
        高级筛选
      </el-button>
    </div>
    <div class="sel" v-else>
      <span> 已选中 {{ multipleSelection.length }} 项</span>
      <el-button
        type="primary"
        size="default"
        plain
        @click="setExam"
        :disabled="disabled"
      >
        设置考场
      </el-button>
      <el-button type="primary" size="default" @click="PassExam" plain>
        考试通过
      </el-button>
      <el-button type="primary" size="default" @click="FailExam" plain>
        考试不通过
      </el-button>
      <el-button type="primary" size="default" @click="finishExam" plain>
        完结
      </el-button>
      <el-button
        type="primary"
        size="default"
        @click="Change"
        plain
        :disabled="disabled"
      >
        更换负责人
      </el-button>
      <el-button
        type="primary"
        plain
        size="default"
        @click="addTeam"
      >
        添加团队成员
      </el-button>
      <el-button type="primary" size="default" @click="exportChioose" plain>
        导出选中
      </el-button>
    </div>
    <div v-if="scenArr !== []" class="scenF">
      <div v-for="(item, index) in scenArr" :key="index" class="scenF-content">
        <div class="scenF-detail" @click="scenSearch(item.sceneId)">
          {{ item.sceneList }}
          <i
            class="el-icon-circle-close"
            @click.stop="scenDel(index)"
            style="margin-left: 10px"
          ></i>
        </div>
      </div>
    </div>
    <div class="table">
      <el-table
        :data="tableData"
        style="width: 100%"
        ref="multipleTable"
        @selection-change="handleSelectionChange"
        :height="tableHight"
      >
        <template slot="empty" class="emptyBg">
          <img src="@/assets/images/empty.jpg" alt="" />
        </template>
        <el-table-column type="selection" width="55"> </el-table-column>
        <template v-for="(item, index) in switchShow">
          <el-table-column
            :key="index"
            :label="item.label"
            v-if="showH(item, index)"
            :prop="item.stage"
            :width="item.width"
            fixed
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span class="staff" @click="drawer(scope.row)">
                {{ scope.row.name }}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            :key="index"
            :label="item.label"
            :prop="item.stage"
            v-show="item.value"
            v-if="item.label !== '姓名' && item.value"
            :width="item.width"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
        </template>
        <el-table-column fixed="right">
          <template slot="header">
            <i class="iconfont icon-shujupeizhi" @click.stop="tableShow"> </i>
          </template>
        </el-table-column>
      </el-table>
      <div class="wuhu">
        <table-sh
          :dialog="dialog"
          :switchShow="switchShow"
          v-if="dialog.dialogTableVisible"
          @submit="getSwitchList"
          class="sh"
        >
        </table-sh>
      </div>
    </div>
    <!-- 分页器 -->
    <el-pagination
      prev-text="上一页"
      next-text="下一页"
      background
      :page-size="pageSize"
      :page-sizes="[10, 20, 30, 40, 50, 100]"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      layout=" ->,total,sizes, prev, pager, next, jumper "
      :total="total"
    >
    </el-pagination>
    <drawer
      :dialog="dialog"
      :drawerData="drawerData"
      v-if="dialog.drawerShowEject"
    ></drawer>
    <!-- 设置考场 -->
    <set-exmroom
      :dialog="dialog"
      v-if="dialog.setExaRoomShowEject"
      :drawerData="drawerData"
    ></set-exmroom>
    <!-- 更换负责人 -->
    <el-dialog
      title="更换负责人"
      :visible.sync="dialog.dialogPerCha"
      width="50%"
      @close="perClose"
      custom-class="dialogClass"
      :close-on-click-modal="false"
    >
      <charge-person
        v-if="dialog.dialogPerChaEject"
        ref="chaPer"
      ></charge-person>
      <span slot="footer">
        <el-button @click="dialog.dialogPerCha = false"> 取消 </el-button>
        <el-button type="primary" @click="onChangeChar"> 确定 </el-button>
      </span>
    </el-dialog>
    <!-- 场景管理 -->
    <drag-table
      :dialog="dialog"
      v-if="dialog.senceAdminEject"
      ref="dragTable"
    ></drag-table>
    <!-- 高级筛选 -->
    <screen
      :dialog="dialog"
      :switchShow="switchShow"
      @sceneArr="sceneArr"
    ></screen>
    <join-team
      :dialog="dialog"
      v-if="dialog.joinTeamShowEject"
      :drawerData="drawerData"
      :type="type"
      :entities='entities'
    ></join-team>
    <transfer
      :dialog="dialog"
      :drawerData="drawerData"
      :type="type"
      v-if="dialog.transferShowEject"
    ></transfer>
  </div>
</template>

<script>
import {
  getList,
  changeDirector,
  batchExport,
  setMissExam,
  setFailExam,
  setPassExam,
} from "@/api/exam.js";
import { distriBution } from "@/api/registration"; //获取负责人接口
import { queryScene } from "@/api/currency";
import setExmroom from "./components/exaArrangement/setExmroom.vue";
import Drawer from "./components/exaMiss/drawer.vue";
import dragTable from "./components/dragTable.vue";
import screen from "./components/screen.vue";
import tableSh from "./components/tableSh.vue";
// 负责人
import chargePerson from "@/components/chargePerson";
import joinTeam from "@/components/joinTeam/index.vue";
import Transfer from "@/components/joinTeam/transfer.vue";
export default {
  components: {
    setExmroom,
    Drawer,
    dragTable,
    screen,
    tableSh,
    chargePerson,
    joinTeam,
    Transfer,
  },
  data() {
    return {
      entities:[],
      type: 23,
      tableHight: window.innerHeight - 330,
      dialog: {
        dialogTableVisible: false,
        drawerShow: false,
        drawerShowEject: false,
        setExaRoomShow: false,
        setExaRoomShowEject: false,
        dialogPerCha: false,
        dialogPerChaEject: false,
        dialogScreenVisible: false,
        senceAdmin: false, //场景管理
        senceAdminEject: false,
        joinTeamShowEject: false,
        joinTeamShow: false,
        editTeamShowEject: false,
        editTeamShow: false,
        transferShow: false,
        transferShowEject: false,
      },
      pageSize: 10,
      pageNum: 1,
      total: 0,
      input: "",
      charge: "",
      chargeId: "",
      selShow: true,
      scenArr: [],
      options: [],
      drawerData: {},
      ids: [],
      chargeList: [],
      value: "",
      tableData: [],
      // 控制表单的显示与隐藏
      switchShow: [
        {
          value: true,
          label: "姓名",
          stage: "name",
        },
        {
          value: true,
          label: "考试批次",
          stage: "batchName",
        },
        { value: true, label: "考试名称", stage: "examName" },
        {
          value: true,
          label: "手机号码",
          stage: "phone",
        },
        {
          value: true,
          label: "公司名称",
          stage: "company",
        },
        {
          value: true,
          label: "理论成绩",
          stage: "theoryPerformance",
        },
        {
          value: true,
          label: "实操成绩",
          stage: "operationalPerformance",
        },
        {
          value: true,
          label: "负责人",
          stage: "userName",
        },
        {
          value: true,
          label: "更新时间",
          stage: "updateTime",
        },
      ],
    };
  },
  created() {
    this.getList();
    this.getScene();
  },
  mounted() {
    document.addEventListener("click", this.bodyCloseMenus);
    window.onresize = () => {
      return (() => {
        this.tableHight = window.innerHeight - 330;
      })();
    };
  },
  beforeDestroy() {
    document.removeEventListener("click", this.bodyCloseMenus);
  },
  activated() {
    this.tableHight = window.innerHeight - 330;
  },
  methods: {
    // 新增团队
    addTeam() {
      this.dialog.joinTeamShowEject = true;
      this.$nextTick(() => {
        this.dialog.joinTeamShow = true;
      });
    },
    // 点击空白
    bodyCloseMenus(e) {
      let self = this;
      if (self.dialog.dialogTableVisible == true) {
        self.dialog.dialogTableVisible = false;
      }
    },
    // 获取高级筛选
    getScene() {
      queryScene({ type: 23 }).then((res) => {
        if (res.default !== null) {
          res.scenes.unshift(res.default);
          this.options = res.scenes;
        } else {
          this.options = res.scenes;
        }
      });
    },
    // 导出选中
    exportChioose() {
      batchExport(this.ids).then((res) => {
        this.download(res.msg);
      });
    },
    // 完结
    finishExam() {
      let that = this;
      this.$confirm("是否确认完结?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return setPassExam(that.ids);
        })
        .then((res) => {
          this.$message.success(res.msg);
          that.getList();
          this.dialog.drawerShow = false;
        });
    },
    // 考试通过
    PassExam() {
      let that = this;
      this.$confirm("是否确认通过?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return setPassExam(that.ids);
        })
        .then((res) => {
          this.$message.success(res.msg);
          that.getList();
          this.dialog.drawerShow = false;
        });
    },
    // 考试不通过
    FailExam() {
      let that = this;
      this.$confirm("是否确认不通过?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return setFailExam(that.ids);
        })
        .then((res) => {
          this.$message.success(res.msg);
          this.dialog.drawerShow = false;
          that.getList();
        });
    },
    // 缺考
    missExam() {
      let that = this;
      this.$confirm("是否确认缺考?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return setMissExam(that.ids);
        })
        .then((res) => {
          this.$message.success(res.msg);
          this.dialog.drawerShow = false;
          that.getList();
        });
    },
    //   确认更换负责人
    onChangeChar() {
      changeDirector({
        id: this.chargeId,
        userId: this.charge,
      }).then((res) => {
        this.$message.success(res.msg);
        this.getList();
        this.dialog.dialogPerCha = false;
      });
    },
    //   更换负责人
    Change() {
      this.dialog.transferShowEject = true;
      this.$nextTick(function () {
        this.dialog.transferShow = true;
      });
    },
    // 关闭更换负责人
    perClose() {
      this.charge = "";
      this.dialog.dialogPerChaEject = false;
    },
    // 获取负责人
    getDistri() {
      distriBution().then((res) => {
        this.chargeList = res.data;
      });
    },
    // 设置考场
    setExam() {
      this.dialog.setExaRoomShowEject = true;
      this.$nextTick(function () {
        this.dialog.setExaRoomShow = true;
      });
    },
    //   打开高级筛选
    screen() {
      this.dialog.dialogScreenVisible = true;
    },
    // 搜索
    search() {
      this.getList();
    },
    // 获取列表
    getList(val) {
      getList({
        pageSize: this.pageSize,
        pageNum: this.pageNum,
        sceneId: val,
        identification: this.input,
        status: 4,
      }).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.pageNum = 1;
      this.getList();
    },
    //分页器
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getList();
    },
    //   打开抽屉
    drawer(row) {
      this.dialog.drawerShowEject = true;
      this.drawerData = row;
      // getDetail(row.id).then((res) => {});
      this.$nextTick(function () {
        this.dialog.drawerShow = true;
      });
    },
    // 点击临时搜索
    scenSearch(id) {
      this.getList(id);
    },
    // 删除临时搜索
    scenDel(i) {
      this.scenArr.splice(i, 1);
      if (this.scenArr.length == 0) {
        this.getList();
      }
    },
    // 获取数组
    sceneArr(data) {
      this.scenArr.push(data);
    },
    querySceneList() {
      this.getList(this.value);
    },
    //管理
    admClick() {
      this.dialog.senceAdminEject = true;
      this.$nextTick(function () {
        this.dialog.senceAdmin = true;
      });
    },
    //新建场景
    selClick() {
      this.screen();
    },
    getSwitchList(list) {
      this.$set(this, "switchShow", list);
    },
    // 场景下拉框按钮
    visibleChange(visible, refName, onClick, onClick2) {
      if (visible) {
        const ref = this.$refs[refName];
        let popper = ref.$refs.popper;
        if (popper.$el) popper = popper.$el;
        if (
          !Array.from(popper.children).some(
            (v) => v.className === "el-cascader-menu__list"
          )
        ) {
          const el = document.createElement("ul");
          el.className = "el-cascader-menu__list";
          el.style =
            "border-top: solid 1px #E4E7ED; padding:0; color: #606266;";
          el.innerHTML = `<li class="el-cascader-node" >
                            <span class="el-cascader-node__label" style='color:#1267FA'>新建场景</span>
                            </li>
                        `;
          const el2 = document.createElement("ul");
          el2.className = "el-cascader-menu__list";
          el2.innerHTML = `<li class="el-cascader-node" >
                            <span class="el-cascader-node__label" style='color:#1267FA'>管理</span>
                            </li>
                        `;
          popper.appendChild(el);
          popper.appendChild(el2);
          el2.onclick = () => {
            onClick2 && onClick2();
            if (ref.toggleDropDownVisible) {
              ref.toggleDropDownVisible(false);
            } else {
              ref.visible = false;
            }
          };
          el.onclick = () => {
            // 底部按钮的点击事件 点击后想触发的逻辑也可以直接写在这
            onClick && onClick();
            // 以下代码实现点击后弹层隐藏 不需要可以删掉
            if (ref.toggleDropDownVisible) {
              ref.toggleDropDownVisible(false);
            } else {
              ref.visible = false;
            }
          };
        }
      }
    },
    // 表格前多选器
    handleSelectionChange(val) {
      this.ids = [];
      this.entities=[]
      if (val.length !== 0) {
        this.chargeId = val[0].id;
        this.drawerData = val[0];
        val.forEach((item) => {
          this.ids.push(item.id);
          this.entities.push(item.id)
        });
      }
      this.selShow = false;
      this.multipleSelection = val;
      if (val.length == 0) {
        this.selShow = true;
      }
      if (val.length > 1) {
        this.disabled = true;
      } else {
        this.disabled = false;
      }
    },
    tableShow() {
      if (this.dialog.dialogTableVisible == false) {
        this.dialog.dialogTableVisible = true;
      } else {
        this.dialog.dialogTableVisible = false;
      }
    },
    showH(item, index) {
      let bole = false;
      if (item.label === "姓名") {
        bole = true;
      }
      if (!item.value) bole = false;
      return bole;
    },
  },
};
</script>

<style lang="less" scoped>
.header {
  width: 100%;
  height: 74px;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #ececec;
  .bread {
    margin-top: 20px;
    margin-left: 5px;
    height: 30px;
    display: flex;
    vertical-align: middle;
    line-height: 30px;
    p {
      margin-left: 10px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #2b2b2b;
    }
  }

  .ipt {
    margin-top: 16px;
    width: 340px;
    /deep/ .el-input__inner {
      border-radius: 4px 0 0 4px;
    }
    .el-button--primary {
      border-radius: 0 4px 4px 0;
    }
  }
  .btn {
    margin-top: 16px;
    .el-button--primary {
      background-color: #ed732e;
      border: #ed732e;
    }
  }
}
.sel {
  margin-top: 20px;
  span {
    margin-right: 40px;
  }
}
.ipt-el {
  width: 240px;
}
.el-dropdown {
  margin-left: 15px;
}
.chooise {
  margin-top: 20px;
  .sel {
    margin: 0 14px;
  }
  .el-button {
    font-size: 14px;
    /deep/ span {
      margin-left: 5px;
    }
  }
}
.sel-sence {
  margin-right: 10px;
}
.el-pagination {
  margin-top: 24px;
  /deep/ .el-pagination__total {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    margin-right: 25px;
  }
  /deep/ .btn-prev {
    width: 80px;
    height: 40px;
    text-align: center;
  }
  /deep/ .btn-next {
    width: 80px;
    height: 40px;
    text-align: center;
  }
  /deep/ .number {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }
  /deep/ .el-input__inner {
    // width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }
  /deep/ .more {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }
  /deep/ .el-pagination__jump {
    .el-input__inner {
      width: 40px;
      height: 40px;
    }
  }
}
.scenF {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  .scenF-content {
    display: flex;
    margin-left: 10px;
    margin-top: 10px;
    .scenF-detail {
      height: 36px;
      line-height: 36px;
      padding-left: 20px;
      padding-right: 20px;
      border: 1px solid #9aa1af;
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #666666;
      .el-icon-circle-close {
        transform: translateY(3px);
      }
    }
  }
}
.staff {
  color: #1267fa;
}
.table {
  position: relative;
  .wuhu {
    position: absolute;
    top: 45px;
    right: 0px;
    z-index: 9999;
    background-color: #fff;
    border: 1px solid #ececec;
  }
}
</style>